//
//  MyAttentionTableView.m
//  1gene
//
//  Created by 1jiyin on 16/3/16.
//  Copyright © 2016年 1jiyin. All rights reserved.
//
//*******************我关注的*******************
#import "MyAttentionTableView.h"
#import "TieZiDetailModel.h"
#import "NSDictionary+NULLToNSString.h"
#import <RongIMKit/RongIMKit.h>
@interface MyAttentionTableView()

@property(nonatomic,copy)UIView *addBtn3View;

@property(nonatomic,assign)NSInteger addBtn3State;

@property(nonatomic,copy)NSDictionary *userDic;

@property(nonatomic,copy)NSMutableArray *tieziDataArray;

//下一页
@property(nonatomic,copy)NSString *nextPageUrl;

@property(nonatomic,copy)NSString *userId;

//加关注
@property(nonatomic,copy)UIButton *btn1;

@property(nonatomic,assign)BOOL attentionState;

@property(nonatomic,copy)NSMutableArray *allBiaoQianArray;

@property (nonatomic, assign) BOOL isFriend; // 是否是好友

@end

@implementation MyAttentionTableView

static int tiebaAnimationState=0;

-(instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style hideheaderView:(BOOL)hide userId:(NSString *)userId withIsFriend:(BOOL)isFriend;
{
    if (self=[super initWithFrame:frame style:style]) {
        _userId=userId;
        _hideHeaderView=hide;
        _attentionState=NO;
        self.showsVerticalScrollIndicator=NO;
        self.delegate=self;
        self.dataSource=self;
        self.backgroundColor=[UIColor whiteColor];
        _dataArray=[NSMutableArray array];
        _arr=[NSArray array];
        self.tableFooterView=[UIView new];
        if (_hideHeaderView) {
            self.tableHeaderView=[UIView new];
        }else{
            self.tableHeaderView=[self createTableHeaderView];
        }
        if (isFriend == YES) {
            self.isFriend = YES;
        } else if (isFriend == NO) {
            self.isFriend = NO;
        }
        
        self.separatorStyle=UITableViewCellSeparatorStyleNone;
        _addBtn3State=0;

        self.header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [self getMyHttpData];
        }];
        self.footer=[MJRefreshAutoGifFooter footerWithRefreshingBlock:^{
            [self getMoreData];
        }];
        
        [self getMyHttpData];

    }
    return self;
}

-(instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style hideheaderView:(BOOL)hide userId:(NSString *)userId
{
    if (self=[super initWithFrame:frame style:style]) {
        _userId=userId;
        _hideHeaderView=hide;
        _attentionState=NO;
        self.showsVerticalScrollIndicator=NO;
        self.delegate=self;
        self.dataSource=self;
        self.backgroundColor=[UIColor whiteColor];
        _dataArray=[NSMutableArray array];
        _arr=[NSArray array];
        self.tableFooterView=[UIView new];
        if (_hideHeaderView) {
            self.tableHeaderView=[UIView new];
        }else{
            self.tableHeaderView=[self createTableHeaderView];
        }
       
        
        self.separatorStyle=UITableViewCellSeparatorStyleNone;
        _addBtn3State=0;
        
        self.header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [self getMyHttpData];
        }];
        self.footer=[MJRefreshAutoGifFooter footerWithRefreshingBlock:^{
            [self getMoreData];
        }];
        
        [self getMyHttpData];
        
    }
    return self;
}


//创建tableHeaderView
-(UIView *)createTableHeaderView
{
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 130+75+30+2+30+1+20)];
    view.backgroundColor=[UIColor colorWithRed:235/255.0 green:235/255.0 blue:241/255.0 alpha:1];
    
//    UIView *backgroundView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 120)];
//    backgroundView.backgroundColor=[UIColor colorWithRed:106/255.0 green:198/255.0 blue:223/255.0 alpha:1];
//    [view addSubview:backgroundView];
    
    
    UIImageView *backgroundImageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, view.frame.size.width, 205)];
    backgroundImageView.image=[UIImage imageNamed:@"community-backgroundImage.png"];
    backgroundImageView.backgroundColor=[UIColor colorWithRed:106/255.0 green:198/255.0 blue:223/255.0 alpha:1];
    [view addSubview:backgroundImageView];
    
    //用户头像
    UIImageView *userHeadImageView=[[UIImageView alloc]initWithFrame:CGRectMake((self.frame.size.width-60)/2.0, 25, 60, 60)];
    [userHeadImageView sd_setImageWithURL:[NSURL URLWithString:_userDic[@"user_profile"][@"avatar_url"]] placeholderImage:[UIImage imageNamed:@"155x155-1.png"]];
    userHeadImageView.layer.cornerRadius=userHeadImageView.frame.size.width/2.0;
    userHeadImageView.layer.masksToBounds=YES;
    [view addSubview:userHeadImageView];
    
    NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:_userDic[@"user_profile"][@"avatar_url"]]];
    UIImage *myHeadImage=[UIImage imageWithData:data];
    userHeadImageView.image=myHeadImage;
    
    
    
    
    
    
    
    
    UIButton *userHeadBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    userHeadBtn.frame=CGRectMake((self.frame.size.width-60)/2.0, 25, 60, 60);
    //    [userHeadBtn setBackgroundImage:[UIImage imageNamed:@"2012729106016418.jpg"] forState:UIControlStateNormal];
    //    userHeadBtn.layer.cornerRadius=userHeadBtn.frame.size.width/2.0;
    //    userHeadBtn.layer.masksToBounds=YES;
    [view addSubview:userHeadBtn];
    
    
    
    //性别
    UIImageView *sexImageView=[[UIImageView alloc]init];
    sexImageView.frame=CGRectMake((self.frame.size.width-20)/2.0, CGRectGetMaxY(userHeadBtn.frame), 20, 20);
    NSInteger sexState=[_userDic[@"user_profile"][@"sex"] integerValue];
    if (sexState==0) {
        sexImageView.image=[UIImage imageNamed:@"sex_man.png"];
    }else{
        sexImageView.image=[UIImage imageNamed:@"sex_woman.png"];
    }
    [view addSubview:sexImageView];
    
    //用户名
    UILabel *name=[[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(userHeadBtn.frame), sexImageView.frame.origin.x-10, 20)];
    name.textAlignment=NSTextAlignmentRight;
    name.text=_userDic[@"user_profile"][@"nikename"];
    name.font=[UIFont systemFontOfSize:15];
    name.textColor=[UIColor whiteColor];
    name.frame=CGRectMake(CGRectGetMaxX(name.frame)-[self calculateWidthWithLable:name], name.frame.origin.y, [self calculateWidthWithLable:name], name.frame.size.height);
    [view addSubview:name];
    
    
    if ([_userDic[@"user_profile"][@"nikename"] isKindOfClass:[NSNull class]]) {
        name.text=@"= =";
    }else{
        NSString *myName=[NSString stringWithFormat:@"%@",_userDic[@"user_profile"][@"nikename"]];
        if (myName.length==0) {
             name.text=@"= =";
        }
    }
    
    
    //    UILabel *sex=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(name.frame)+2, name.frame.origin.y, 10, 20)];
    //    sex.text=@"♀";
    //    sex.textColor=[UIColor redColor];
    //    sex.font=[UIFont systemFontOfSize:13];
    //    [headerview addSubview:sex];
    
    
    
    //账号
    UILabel *userAccount=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(sexImageView.frame)+10, name.frame.origin.y, self.frame.size.width-CGRectGetMaxX(sexImageView.frame)-10, 20)];
    userAccount.text=_userDic[@"user_profile"][@"phone"];
    userAccount.textColor=[UIColor whiteColor];
    userAccount.font=[UIFont systemFontOfSize:11];
    [view addSubview:userAccount];
    
    if ([_userDic[@"user_profile"][@"phone"] isKindOfClass:[NSNull class]]) {
        userAccount.text=@"未知账号";
    }else{
        NSString *myName=[NSString stringWithFormat:@"%@",_userDic[@"user_profile"][@"phone"]];
        if (myName.length==0) {
            userAccount.text=@"未知账号";
        }
    }
    
    
    
    //年龄
    UILabel *age=[[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(name.frame), (self.frame.size.width-5)/2.0, 20)];
    if ([_userDic[@"user_profile"][@"age"] isKindOfClass:[NSNull class]]) {
        age.text=@"0岁";
    }else{
        age.text=[NSString stringWithFormat:@"%@岁",_userDic[@"user_profile"][@"age"]];
        NSString *myAge=[NSString stringWithFormat:@"%@",_userDic[@"user_profile"][@"age"]];
        NSLog(@"长度%ld",myAge.length);
        if ([myAge isEqualToString:@""]) {
            NSLog(@"相等======");
            age.text=@"0岁";
        }else{
            NSLog(@"不相等======");
            age.text=[NSString stringWithFormat:@"%@岁",_userDic[@"user_profile"][@"age"]];
        }
    }

    age.textAlignment=NSTextAlignmentRight;
    age.textColor=[UIColor whiteColor];
    age.font=[UIFont systemFontOfSize:11];
    [view addSubview:age];
    
    
    
    //地区
    UILabel *addressLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(age.frame)+10, age.frame.origin.y, self.frame.size.width-(CGRectGetMaxX(age.frame)+10), 20)];
    addressLab.text=[NSString stringWithFormat:@"%@",_userDic[@"user_profile"][@"city"]];
    addressLab.textColor=[UIColor whiteColor];
    addressLab.font=[UIFont systemFontOfSize:11];
    [view addSubview:addressLab];
    
    if ([_userDic[@"user_profile"][@"city"] isKindOfClass:[NSNull class]]) {
        addressLab.text=@"未知";
    }else{
        NSString *myName=[NSString stringWithFormat:@"%@",_userDic[@"user_profile"][@"city"]];
        if (myName.length==0) {
            addressLab.text=@"未知";
        }
    }
    
    
    
    
    //标签
    UILabel *biaoqian=[[UILabel alloc]initWithFrame:CGRectMake(sexImageView.frame.origin.x-50, CGRectGetMaxY(age.frame), 30, 20)];
    biaoqian.text=@"标签";
    biaoqian.textColor=[UIColor whiteColor];
    biaoqian.font=[UIFont systemFontOfSize:11];
    [view addSubview:biaoqian];
    if ([_userDic[@"tags"] count]==0) {
        //biaoqian.hidden=YES;
        biaoqian.text=@"标签:   ==       ==";
        biaoqian.frame=CGRectMake(sexImageView.frame.origin.x-50, CGRectGetMaxY(age.frame), self.frame.size.width-(sexImageView.frame.origin.x-50), 20);
    }
    
    _allBiaoQianArray=[NSMutableArray array];
    NSArray *biaoqianArr=_userDic[@"tags"];
    CGFloat biaoqian_w = 0.0;
    //        biaoqian1.frame=CGRectMake(CGRectGetMaxX(biaoqian.frame)+5, biaoqian.frame.origin.y, [self calculateWidthWithLable:biaoqian1], 20);
    
    for (int i=0; i<biaoqianArr.count; i++) {
        if (i<2) {
            //标签1
            UILabel *biaoqian1=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(biaoqian.frame)+2+biaoqian_w+15*i, biaoqian.frame.origin.y, 0, 20)];
            biaoqian1.text=[NSString stringWithFormat:@"%@",biaoqianArr[i][@"name"]];
            [_allBiaoQianArray addObject:[NSString stringWithFormat:@"%@",biaoqianArr[i][@"name"]]];
            biaoqian1.textAlignment=NSTextAlignmentCenter;
            biaoqian1.font=[UIFont systemFontOfSize:11];
            biaoqian1.textColor=[UIColor whiteColor];
            biaoqian1.frame=CGRectMake(CGRectGetMaxX(biaoqian.frame)+2+biaoqian_w+15*i, biaoqian.frame.origin.y, [self calculateWidthWithLable:biaoqian1], 20);
            [view addSubview:biaoqian1];
            biaoqian_w+=[self calculateWidthWithLable:biaoqian1];
        }
    }
    
    //更多标签
    if ([_userDic[@"tags"] count]>0) {
        UIImageView *moreBiaoQianImageView=[[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(biaoqian.frame)+2+biaoqian_w+biaoqianArr.count*15, biaoqian.frame.origin.y, 20, 20)];
        moreBiaoQianImageView.image=[UIImage imageNamed:@"baritem_left_hl"];
        [view addSubview:moreBiaoQianImageView];
        //盖按钮
        UIButton *biaoqianBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        biaoqianBtn.frame=CGRectMake(CGRectGetMaxX(biaoqian.frame), biaoqian.frame.origin.y, self.frame.size.width-CGRectGetMaxX(biaoqian.frame), moreBiaoQianImageView.frame.size.height);
        [biaoqianBtn addTarget:self action:@selector(moreBiaoQianBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:biaoqianBtn];
    }
    
    
    
    //个性签名
    UILabel *personalName=[[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(biaoqian.frame), self.frame.size.width, 20)];
    personalName.text=[NSString stringWithFormat:@"个性签名:%@",_userDic[@"user_profile"][@"signatures"]];
    personalName.textColor=[UIColor whiteColor];
    personalName.font=[UIFont systemFontOfSize:11];
    personalName.textAlignment=NSTextAlignmentCenter;
    [view addSubview:personalName];
    _myPersonalName=personalName.text;
    if ([_userDic[@"user_profile"][@"signatures"] isKindOfClass:[NSNull class]]) {
        //personalName.hidden=YES;
        personalName.text=@"个性签名: = =  ";
    }else{
        NSString *myPersonalName=[NSString stringWithFormat:@"%@",_userDic[@"user_profile"][@"signatures"]];
        if (myPersonalName.length==0) {
            personalName.text=@"个性签名: = =  ";
        }
    }
//    NSString *personalStr=_userDic[@"user_profile"][@"signatures"];
//    if (name.text.length==2) {
//        personalName.frame=CGRectMake(name.frame.origin.x+2, CGRectGetMaxY(biaoqian.frame), self.frame.size.width-name.frame.origin.x+50, 20);
//    }
//    else if (personalStr.length>=20) {
//        
//    }else{
//        personalName.frame=CGRectMake(name.frame.origin.x-10, CGRectGetMaxY(biaoqian.frame), self.frame.size.width-name.frame.origin.x+50, 20);
//    }
//    
    
    //显示个性签名详情
    UIButton *allPersonalNameBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    allPersonalNameBtn.frame=personalName.frame;
    [allPersonalNameBtn addTarget:self action:@selector(allPersonalNameBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:allPersonalNameBtn];
    
    
    
    
    
    
    //返回上一页
    UIButton *backBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame=CGRectMake(10, 20, 25, 25);
    [backBtn setBackgroundImage:[UIImage imageNamed:@"left_back"] forState:UIControlStateNormal];
    //[backBtn setTitle:@"返回" forState:UIControlStateNormal];
    //[backBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:backBtn];
    
        //关注 加好友 更多
        CGFloat addbtn_w=60;
        CGFloat addbtn_h=20;
        UIButton *addBtn1=[UIButton buttonWithType:UIButtonTypeCustom];
        addBtn1.frame=CGRectMake((self.frame.size.width-addbtn_w*3-5*2)/2.0, CGRectGetMaxY(personalName.frame)+5, addbtn_w, addbtn_h);
        [addBtn1 setTitle:@"+关注" forState:UIControlStateNormal];
        addBtn1.titleLabel.font=[UIFont systemFontOfSize:13];
        addBtn1.backgroundColor=[UIColor colorWithRed:240/255.0 green:156/255.0 blue:38/255.0 alpha:1];
        addBtn1.layer.borderColor=[UIColor colorWithRed:240/255.0 green:156/255.0 blue:38/255.0 alpha:1].CGColor;
        addBtn1.layer.borderWidth=1.0;
        addBtn1.layer.cornerRadius=3.0;
        addBtn1.tag=[_userDic[@"id"] integerValue]+1000000;
        [addBtn1 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [addBtn1 addTarget:self action:@selector(addBtn1Click:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:addBtn1];
        _btn1=addBtn1;
    
        //是否已关注
    NSInteger attentionState;
    if ([_userDic[@"is_attentioned"] isKindOfClass:[NSNull class]]) {
        attentionState=0;
    }else{
        attentionState=[_userDic[@"is_attentioned"] integerValue];
    }
    if (attentionState) {
        [addBtn1 setTitle:@"取消关注" forState:UIControlStateNormal];
    }
    _attentionState=attentionState;
    
    
    
    
    
    
    
    
        UIButton *addBtn2=[UIButton buttonWithType:UIButtonTypeCustom];
        addBtn2.frame=CGRectMake(CGRectGetMaxX(addBtn1.frame)+5, CGRectGetMaxY(personalName.frame)+5, addbtn_w, addbtn_h);
        [addBtn2 setTitle:@"发消息" forState:UIControlStateNormal];
        addBtn2.backgroundColor=[UIColor colorWithRed:71/255.0 green:184/255.0 blue:158/255.0 alpha:1];
        addBtn2.layer.borderColor=[UIColor colorWithRed:71/255.0 green:184/255.0 blue:158/255.0 alpha:1].CGColor;
        addBtn2.layer.borderWidth=1.0;
        addBtn2.layer.cornerRadius=3.0;
        addBtn2.titleLabel.font=[UIFont systemFontOfSize:13];
        [addBtn2 addTarget:self action:@selector(addBtn2Click:) forControlEvents:UIControlEventTouchUpInside];
        [addBtn2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
        [view addSubview:addBtn2];
    
        UIButton *addBtn3=[UIButton buttonWithType:UIButtonTypeCustom];
        addBtn3.frame=CGRectMake(CGRectGetMaxX(addBtn2.frame)+5, CGRectGetMaxY(personalName.frame)+5, addbtn_w, addbtn_h);
        [addBtn3 setTitle:@"更多" forState:UIControlStateNormal];
        addBtn3.backgroundColor=[UIColor colorWithRed:227/255.0 green:105/255.0 blue:136/255.0 alpha:1];
        addBtn3.layer.borderColor=[UIColor colorWithRed:227/255.0 green:105/255.0 blue:136/255.0 alpha:1].CGColor;
        addBtn3.layer.borderWidth=1.0;
        addBtn3.layer.cornerRadius=3.0;
        addBtn3.titleLabel.font=[UIFont systemFontOfSize:13];
        [addBtn3 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [addBtn3 addTarget:self action:@selector(addBtn3Click:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:addBtn3];
    

    

    //她关注的 她的好友 她的粉丝 她的收藏
    CGFloat btn_w=(self.frame.size.width-0.5)/2.0;
    CGFloat btn_h=50;
    UIButton *sheCare=[UIButton buttonWithType:UIButtonTypeCustom];
    sheCare.tag=4;
    sheCare.frame=CGRectMake(0, CGRectGetMaxY(backgroundImageView.frame), btn_w, btn_h);
    sheCare.backgroundColor=[UIColor whiteColor];
    [sheCare setTitle:@"#她关注的#" forState:UIControlStateNormal];
    [sheCare setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [sheCare addTarget:self action:@selector(addBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:sheCare];
    
    UIButton *herfriend=[UIButton buttonWithType:UIButtonTypeCustom];
    herfriend.tag=5;
    herfriend.frame=CGRectMake(btn_w+0.5, CGRectGetMaxY(backgroundImageView.frame), btn_w, btn_h);
    herfriend.backgroundColor=[UIColor whiteColor];
    [herfriend setTitle:@"#她的好友#" forState:UIControlStateNormal];
    [herfriend setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [herfriend addTarget:self action:@selector(addBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:herfriend];
    
    UIButton *fensi=[UIButton buttonWithType:UIButtonTypeCustom];
    fensi.tag=6;
    fensi.frame=CGRectMake(0, CGRectGetMaxY(sheCare.frame)+0.5, btn_w, btn_h);
   fensi.backgroundColor=[UIColor whiteColor];
    [fensi setTitle:@"#她的粉丝#" forState:UIControlStateNormal];
    [fensi setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [fensi addTarget:self action:@selector(addBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:fensi];
    
    UIButton *shoucang=[UIButton buttonWithType:UIButtonTypeCustom];
    shoucang.frame=CGRectMake(btn_w+0.5, CGRectGetMaxY(sheCare.frame)+0.5, btn_w, btn_h);
    shoucang.tag=7;
    shoucang.backgroundColor=[UIColor whiteColor];
    [shoucang setTitle:@"#她的收藏#" forState:UIControlStateNormal];
    [shoucang setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [shoucang addTarget:self action:@selector(addBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:shoucang];
    view.frame=CGRectMake(0, 0, self.frame.size.width, CGRectGetMaxY(shoucang.frame)+1);
    
    
    _addBtn3View = [[UIView alloc]initWithFrame:CGRectMake(addBtn3.frame.origin.x, CGRectGetMaxY(addBtn3.frame), 150, 205)];
    [view addSubview:_addBtn3View];
    //_addBtn3View.backgroundColor=[UIColor redColor];
    _addBtn3View.center=CGPointMake(addBtn3.center.x, addBtn3.center.y+_addBtn3View.frame.size.height/2.0+addBtn3.frame.size.height/2.0);
    // 更多的背景
    UIImageView *addBtn3ImageView=[[UIImageView alloc]initWithFrame:_addBtn3View.bounds];
    addBtn3ImageView.image=[UIImage imageNamed:@"addBtn3_backgroundView"];
    [_addBtn3View addSubview:addBtn3ImageView];
    //举报 发消息 删除 分组

    NSArray *tempArray = [NSArray array];
    if (self.isFriend == YES) {
        tempArray = @[@{@"image":@"shequ_report",@"name":@"举   报"},@{@"image":@"shequ_sendMessage",@"name":@"发消息"},@{@"image":@"shequ_delete",@"name":@"删   除"},@{@"image":@"shequ_group",@"name":@"分   组"}];
    } else if (self.isFriend == NO) {
        tempArray = @[@{@"image":@"shequ_report",@"name":@"举   报"},@{@"image":@"shequ_sendMessage",@"name":@"发消息"}];
    }
 //   NSArray *addBtn3Array=@[@{@"image":@"shequ_report",@"name":@"举   报"},@{@"image":@"shequ_sendMessage",@"name":@"发消息"},@{@"image":@"shequ_delete",@"name":@"删   除"},@{@"image":@"shequ_group",@"name":@"分   组"}];
    NSArray *addBtn3Array = [NSArray arrayWithArray:tempArray];
    CGFloat addBtn3ImageView_w=40;
    CGFloat addBtn3ImageView_h=40;
    CGFloat addBtn3_w=_addBtn3View.frame.size.width-addBtn3ImageView_w-20-15;
    CGFloat addBtn3_h=addBtn3ImageView_h;
    
    for (int i=0; i<addBtn3Array.count; i++) {
        UIImageView *reportImageView=[[UIImageView alloc]initWithFrame:CGRectMake(15, 25+(addBtn3ImageView_h+5)*i, addBtn3ImageView_w, addBtn3ImageView_h)];
        reportImageView.image=[UIImage imageNamed:addBtn3Array[i][@"image"]];
        [_addBtn3View addSubview:reportImageView];
        
        UIButton *reportBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        reportBtn.tag=i+1;
        reportBtn.frame=CGRectMake(CGRectGetMaxX(reportImageView.frame), reportImageView.frame.origin.y, addBtn3_w, addBtn3_h);
        reportBtn.titleLabel.font=[UIFont systemFontOfSize:18];
        [reportBtn setTitle:addBtn3Array[i][@"name"] forState:UIControlStateNormal];
        [reportBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [reportBtn addTarget:self action:@selector(reportBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_addBtn3View addSubview:reportBtn];
    }
    _addBtn3View.hidden=YES;
    [self insertSubview:_addBtn3View atIndex:999];
    return view;
}
//举报 发消息 删除 分组
-(void)reportBtnClick:(UIButton *)sender
{
    NSLog(@"===========%ld",sender.tag);
    [self.imgDelegate moreSelectedIndex:sender.tag];
}
//加关注
-(void)addBtn1Click:(UIButton *)sender
{
     NSLog(@"点击加关注");
    if (_attentionState) {
        [self cancelAttentionUser:[NSString stringWithFormat:@"%ld",sender.tag-1000000]];
    }else{
        [self getAttentionUser:[NSString stringWithFormat:@"%ld",sender.tag-1000000]];
    }
}
//加好友 发消息
-(void)addBtn2Click:(UIButton *)sender
{
    NSLog(@"点击加好友");
    [self.imgDelegate startChat:_userId];
    
}
//更多   举报
-(void)addBtn3Click:(UIButton *)sender
{
    //[self reportUser];
  //  [self.imgDelegate startReport];
    NSLog(@"点击举报");
    if (_addBtn3State==0) {
        NSLog(@"显示");
        _addBtn3View.hidden=NO;
        _addBtn3State=1;
    }
    else if (_addBtn3State==1) {
         NSLog(@"隐藏");
        _addBtn3View.hidden=YES;
        _addBtn3State=0;
    }
}
//更多标签按钮点击事件
-(void)moreBiaoQianBtnClick:(UIButton *)sender
{
    [self.imgDelegate moreBiaoQianBtnClick:_allBiaoQianArray];
}

//个性签名完整显示
-(void)allPersonalNameBtnClick:(UIButton *)sender
{
    NSLog(@"点击个性签名");
    [self.imgDelegate allPersonalNameBtnClick:_myPersonalName];
}




#pragma mark +关注 +好友
-(void)addBtnClick:(UIButton *)sender
{
   // NSLog(@"点击了%ld",sender.tag);
    [self.imgDelegate chooseFunction:sender.tag];
}
#pragma mark 返回上一页
-(void)backBtnClick:(UIButton *)sender
{
    [self.imgDelegate gotoUpViewController];
}
//tableView的代理方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    for (id subView in cell.contentView.subviews) {
        [subView removeFromSuperview];
    }
    cell.backgroundColor=[UIColor whiteColor];
    
    TieZiDetailModel *model=_dataArray[indexPath.row];
    //cell.userInteractionEnabled=NO;
    //用户头像
    UIImageView *headImageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 20, 56, 56)];
    //headImageView.image=[UIImage imageNamed:_dataArray[indexPath.row][@"userHeadImage"]];
    [headImageView sd_setImageWithURL:[NSURL URLWithString:model.user_info[@"avatar_url"]] placeholderImage:[UIImage imageNamed:@"155x155-1.png"]];
    headImageView.layer.cornerRadius=56/2.0;
    headImageView.layer.masksToBounds=YES;
    [cell.contentView addSubview:headImageView];
    
    NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:model.user_info[@"avatar_url"]]];
    UIImage *myHeadImage=[UIImage imageWithData:data];
    headImageView.image=myHeadImage;
    
    
    
    
    
    
    if (indexPath.row==0) {
        headImageView.frame=CGRectMake(headImageView.frame.origin.x, headImageView.frame.origin.y-5, headImageView.frame.size.width, headImageView.frame.size.height);
    }
    
    
    
    
    
    //盖按钮
    UIButton *headImageBtn1=[UIButton buttonWithType:UIButtonTypeCustom];
    headImageBtn1.frame=headImageView.frame;
    [headImageBtn1 addTarget:self action:@selector(headImageBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [cell.contentView addSubview:headImageBtn1];
    
    
    CGFloat height=(56-8)/3.0;
    //用户名
    UILabel *name=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(headImageView.frame)+8, headImageView.frame.origin.y, 80, height)];
    name.text=model.user_info[@"nikename"];
    name.textColor=[UIColor colorWithRed:87/255.0 green:194/255.0 blue:209/255.0 alpha:1];
    name.font=[UIFont systemFontOfSize:13];
    name.frame=CGRectMake(CGRectGetMaxX(headImageView.frame)+8, headImageView.frame.origin.y, [self calculateWidthWithLable:name], height);
    [cell.contentView addSubview:name];
    
    //性别
    UIImageView *sexImageView=[[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(name.frame)+2, headImageView.frame.origin.y, height, height)];
    //sexImageView.image=[UIImage imageNamed:_dataArray[indexPath.row][@"sex"]];
    [cell.contentView addSubview:sexImageView];
    NSInteger sexState=[model.user_info[@"sex"] integerValue];
    if (sexState==0) {
        sexImageView.image=[UIImage imageNamed:@"sex_man"];
    }else{
        sexImageView.image=[UIImage imageNamed:@"sex_woman"];
    }
    //    UILabel *sex=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(name.frame)+2, 10, 10, height)];
    //    sex.text=_dataArray[indexPath.row][@"sex"];
    //    sex.textColor=[UIColor colorWithRed:87/255.0 green:194/255.0 blue:209/255.0 alpha:1];
    //    sex.font=[UIFont systemFontOfSize:10];
    //    [cell.contentView addSubview:sex];
    
    //标签
    UILabel *biaoqian=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(headImageView.frame)+8, CGRectGetMaxY(name.frame)+4, 40, height)];
    biaoqian.text=model.tag_name;
    biaoqian.textColor=[UIColor colorWithRed:87/255.0 green:194/255.0 blue:209/255.0 alpha:1];
    biaoqian.font=[UIFont systemFontOfSize:12];
    biaoqian.layer.borderColor=[UIColor colorWithRed:87/255.0 green:194/255.0 blue:209/255.0 alpha:1].CGColor;
    biaoqian.layer.borderWidth=1.0;
    biaoqian.layer.cornerRadius=2.0;
    biaoqian.textAlignment=NSTextAlignmentCenter;
    biaoqian.frame=CGRectMake(biaoqian.frame.origin.x, biaoqian.frame.origin.y, [self calculateWidthWithLable:biaoqian]+8, biaoqian.frame.size.height);
    [cell.contentView addSubview:biaoqian];
    
    //时间
    UILabel *time=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(headImageView.frame)+8, CGRectGetMaxY(biaoqian.frame)+4, 60, height)];
    time.text=model.created_at;
    time.textColor=[UIColor colorWithRed:87/255.0 green:194/255.0 blue:209/255.0 alpha:1];
    time.font=[UIFont systemFontOfSize:13];
    time.frame=CGRectMake(time.frame.origin.x, time.frame.origin.y, [self calculateWidthWithLable:time], time.frame.size.height);
    [cell.contentView addSubview:time];
    
    
   // CGFloat height2=56/3.0;
    
    
    //评论
    UIImageView *commentImageView=[[UIImageView alloc]initWithFrame:CGRectMake(self.frame.size.width-10-30-20-30-20-1, headImageView.frame.origin.y, 20, 20)];
    commentImageView.image=[UIImage imageNamed:@"shequ_comment.png"];
    [cell.contentView addSubview:commentImageView];
    
    
    
    UILabel *commentLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(commentImageView.frame)+1, headImageView.frame.origin.y, 30, 20)];
    commentLab.text=[self getLabel:model.comment_num];
    
    commentLab.font=[UIFont systemFontOfSize:10];
    commentLab.textColor=[UIColor grayColor];
    [cell.contentView addSubview:commentLab];
    
    
    
    //点赞
    UIImageView *zanImageView=[[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(commentLab.frame), headImageView.frame.origin.y, 20,20)];
    //NSInteger zanState=[_dataArray[indexPath.row][@"zanState"] integerValue];
    NSInteger zanState=[model.is_like integerValue];
    if (zanState==0) {
        zanImageView.image=[UIImage imageNamed:@"shequ_dianzan_no.png"];
    }else{
        zanImageView.image=[UIImage imageNamed:@"shequ_dianzan_yes.png"];
    }
    //添加手势
    zanImageView.userInteractionEnabled=YES;
    zanImageView.tag=indexPath.row+1;
    
    
    UITapGestureRecognizer *tap1=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapHappen1:)];
    [zanImageView addGestureRecognizer:tap1];
    
    
    [cell.contentView addSubview:zanImageView];
    
    if (tiebaAnimationState==1) {
        CAKeyframeAnimation *k = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"];
        k.values = @[@(0.1),@(1.0),@(1.5)];
        k.keyTimes = @[@(0.0),@(0.5),@(0.8),@(1.0)];
        k.calculationMode = kCAAnimationLinear;
        [zanImageView.layer addAnimation:k forKey:@"SHOW"];
    }
    
    
    UILabel *zanLab=[[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(zanImageView.frame)+1, headImageView.frame.origin.y, 30, 20)];
    zanLab.text=[self getLabel:model.like_num];
    zanLab.font=[UIFont systemFontOfSize:10];
    zanLab.textColor=[UIColor grayColor];
    [cell.contentView addSubview:zanLab];
    
    
    //精华帖标识
    UIImageView *jinghuatie=[[UIImageView alloc]initWithFrame:CGRectMake(commentImageView.frame.origin.x, CGRectGetMaxY(commentImageView.frame)+3, 20+30+2+20+30, 34*(102/168.0))];
    jinghuatie.image=[UIImage imageNamed:@"tieziImage_01"];
    if ([model.is_popular integerValue]!=0) {
        jinghuatie.image=[UIImage imageNamed:@"tieziImage_02"];
    }
    if ([model.is_great integerValue]!=0) {
        jinghuatie.image=[UIImage imageNamed:@"tieziImage_03"];
    }
    [cell.contentView addSubview:jinghuatie];
    
    
    //帖子标题
    UILabel *topicLab=[[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(headImageView.frame)+5, self.frame.size.width-10-10, 100-10-50)];
    topicLab.text=model.title;
    topicLab.textColor=[UIColor blackColor];
    topicLab.font=[UIFont systemFontOfSize:15];
    topicLab.numberOfLines=0;
    CGSize topicLabSize=[topicLab boundingRectWithSize:CGSizeMake(topicLab.frame.size.width, 0)];
    topicLab.frame=CGRectMake(10, CGRectGetMaxY(headImageView.frame)+5, self.frame.size.width-10-10, topicLabSize.height);
    
    [cell.contentView addSubview:topicLab];
    
    
    //帖子内容
    UILabel *contentLab=[[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(topicLab.frame)+5, self.frame.size.width-10-10, 112-10-50-40-1)];
    contentLab.text=model.content;
    contentLab.textColor=[UIColor blackColor];
    contentLab.font=[UIFont systemFontOfSize:13];
    contentLab.numberOfLines=0;
    CGSize contentLabsize=[contentLab boundingRectWithSize:CGSizeMake(contentLab.frame.size.width, 0)];
    contentLab.frame=CGRectMake(10, CGRectGetMaxY(topicLab.frame)+5, self.frame.size.width-10-10, contentLabsize.height);
    
    [cell.contentView addSubview:contentLab];
    
    
    
    
    //发表的图片
    CGFloat img_w=(self.frame.size.width-10*6)/5.0;
    CGFloat img_h=img_w*1.1;
    NSInteger hang=[self calculatingHang:model.media_urls];
    //NSLog(@"图片有多少行=====%ld",hang);
    for (int i=0; i<hang; i++) {
        for (int j=0; j<5; j++) {
            if (i*5+j<[model.media_urls count]) {
                UIImageView *imgView=[[UIImageView alloc]initWithFrame:CGRectMake(10+(img_w+10)*j, CGRectGetMaxY(contentLab.frame)+10+(img_h+5)*i, img_w, img_h)];
                //imgView.image=[UIImage imageNamed:_dataArray[indexPath.row][@"imageArr"][i*5+j]];
                [imgView sd_setImageWithURL:[NSURL URLWithString:model.media_urls[i*5+j]] placeholderImage:[UIImage imageNamed:@"noImage_background"]];
                [cell.contentView addSubview:imgView];
                imgView.tag=1000*indexPath.row+i*5+j;
                
                
                UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(imgTapHappen:)];
                imgView.userInteractionEnabled=YES;
                [imgView addGestureRecognizer:tap];
            }
        }
    }
    if ([model.media_urls count]>0) {
        UIView *line=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(contentLab.frame)+10+img_h+9, self.frame.size.width, 1)];
        line.backgroundColor=[UIColor colorWithRed:212/255.0 green:213/255.0 blue:214/255.0 alpha:1];
        [cell.contentView addSubview:line];
        if (hang==1) {
            line.frame=CGRectMake(0, CGRectGetMaxY(contentLab.frame)+10+img_h+9, self.frame.size.width, 1);
        }else if (hang==2){
            line.frame=CGRectMake(0, CGRectGetMaxY(contentLab.frame)+10+img_h*2+5+9, self.frame.size.width, 1);
        }
    }else{
        UIView *line=[[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(contentLab.frame)+9, self.frame.size.width, 1)];
        line.backgroundColor=[UIColor colorWithRed:212/255.0 green:213/255.0 blue:214/255.0 alpha:1];
        [cell.contentView addSubview:line];
    }
    
    //cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
    
    
    
    
    return cell;
}

//点击发表的图片
-(void)imgTapHappen:(UITapGestureRecognizer *)tap
{
    UIImageView *imgView=(id)tap.view;
    NSLog(@"手势响应了");
    TieZiDetailModel *model=_dataArray[imgView.tag/1000];
    //[self.imgDelegate bigImage:imgView.image];
    [self.imgDelegate bigImage:imgView.tag%1000 AndImageArrays:model.media_urls];
}

-(void)btnClick1:(UIButton *)sender
{
    NSLog(@".........................");
}
//计算评论 点赞的个数
-(NSString *)getLabel:(NSString *)number
{
    NSInteger num=[number floatValue];
    if (num>10000) {
        number=[NSString stringWithFormat:@"%.1f万",num/10000.0];
    }
    return number;
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    TieZiDetailModel *model=_dataArray[indexPath.row];
    //帖子标题
    UILabel *topicLab=[[UILabel alloc]initWithFrame:CGRectMake(10, 0, self.frame.size.width-10-10, 100-10-50)];
    topicLab.text=model.title;
    topicLab.textColor=[UIColor blackColor];
    topicLab.font=[UIFont systemFontOfSize:15];
    topicLab.numberOfLines=0;
    CGSize topicLabSize=[topicLab boundingRectWithSize:CGSizeMake(topicLab.frame.size.width, 0)];
    
    //帖子内容
    UILabel *contentLab=[[UILabel alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(topicLab.frame), self.frame.size.width-10-10, 112-10-50-40-1)];
    contentLab.text=model.content;
    contentLab.textColor=[UIColor blackColor];
    contentLab.font=[UIFont systemFontOfSize:13];
    contentLab.numberOfLines=0;
    CGSize contentLabsize=[contentLab boundingRectWithSize:CGSizeMake(contentLab.frame.size.width, 0)];
    //发表的图片
    CGFloat img_w=(self.frame.size.width-10*6)/5.0;
    CGFloat img_h=img_w*1.1;
    if ([model.media_urls count]>0) {
        NSInteger hang=[self calculatingHang:model.media_urls];
        if (hang==1) {
            if (indexPath.row==0) {
                return 60+30+img_h+10+topicLabSize.height+contentLabsize.height-5;
            }else{
                return 60+30+img_h+10+topicLabSize.height+contentLabsize.height;
            }
            
        }else if (hang==2){
            if (indexPath.row==0) {
                return 60+30+img_h*2+5+10+topicLabSize.height+contentLabsize.height-5;
            }else{
                return 60+30+img_h*2+5+10+topicLabSize.height+contentLabsize.height;
            }
            
        }
        
    }
    
    if (indexPath.row==0) {
        return 60+30+topicLabSize.height+contentLabsize.height-5;
    }else{
        return 60+30+topicLabSize.height+contentLabsize.height;
    }

}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    TieZiDetailModel *model=_dataArray[indexPath.row];
    [self.imgDelegate gotoXiangQingViewController:model.topic_id];
}
//根据文字计算宽度和高度
-(CGFloat)calculateWidthWithLable:(UILabel *)label
{
    CGSize size=[label.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:label.font,NSFontAttributeName, nil]];
    return size.width;
}


//头像按钮的响应
-(void)headImageBtnClick:(UIButton *)sender
{
    NSLog(@"头像");
    [self.imgDelegate userHeadClick];
}

//点赞
-(void)zanImageBtnClick:(UIButton *)sender
{
    NSLog(@"点赞");
}

//发表的图片
-(void)imgBtnClick:(UIButton *)sender
{
    NSLog(@"图片响应");
   // [self.imgDelegate bigImage:sender.imageView.image];
}
//点赞
-(void)tapHappen1:(UITapGestureRecognizer *)tap
{
    UIImageView *imgView=(id)tap.view;
    NSLog(@"=========%ld",imgView.tag-1);
    TieZiDetailModel *model1=_dataArray[imgView.tag-1];
    tiebaAnimationState=1;
    
    NSInteger zanState=[model1.is_like integerValue];

    if (zanState==0) {
        //点赞
        
        NSLog(@"点赞");
        
        NSDictionary *dic=_tieziDataArray[imgView.tag-1];
        NSInteger zanNumber=[dic[@"like_num"] integerValue];
        zanNumber+=1;
        [dic setValue:@"1" forKey:@"is_like"];
        [dic setValue:[NSString stringWithFormat:@"%ld",zanNumber] forKey:@"like_num"];
        TieZiDetailModel *model2=[[TieZiDetailModel alloc]initWithDictionary:dic];
        
        [_dataArray removeObjectAtIndex:imgView.tag-1];
        [_dataArray insertObject:model2 atIndex:imgView.tag-1];
        
        [_tieziDataArray removeObjectAtIndex:imgView.tag-1];
        [_tieziDataArray insertObject:dic atIndex:imgView.tag-1];
        
        //一个cell刷新
        NSIndexPath *indexPath=[NSIndexPath indexPathForRow:imgView.tag-1 inSection:0];
        [self reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
        
        //通知后台
        TieZiDetailModel *model3=_dataArray[imgView.tag-1];
        [self getZanHttpData:model3.topic_id];
        
    }else{
        //取消赞
        NSLog(@"取消赞");
        
        NSDictionary *dic=_tieziDataArray[imgView.tag-1];
        [dic setValue:@"0" forKey:@"is_like"];
        NSInteger zanNumber=[dic[@"like_num"] integerValue];
        zanNumber-=1;
        [dic setValue:[NSString stringWithFormat:@"%ld",zanNumber] forKey:@"like_num"];
        TieZiDetailModel *model2=[[TieZiDetailModel alloc]initWithDictionary:dic];
        
        [_dataArray removeObjectAtIndex:imgView.tag-1];
        [_dataArray insertObject:model2 atIndex:imgView.tag-1];
        
        [_tieziDataArray removeObjectAtIndex:imgView.tag-1];
        [_tieziDataArray insertObject:dic atIndex:imgView.tag-1];
        
        //一个cell刷新
        NSIndexPath *indexPath=[NSIndexPath indexPathForRow:imgView.tag-1 inSection:0];
        [self reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
        
        //通知后台
        TieZiDetailModel *model3=_dataArray[imgView.tag-1];
        [self getCancelZanHttpData:model3.topic_id];
    }
}

//计算行
-(NSInteger)calculatingHang:(NSArray *)arr
{
    NSInteger hang=0;
    if (arr.count>5) {
        hang=2;
    }else if(arr.count==0){
        hang=0;
    }else{
        hang=1;
    }
    return hang;
}

//UIScrollView的代理
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    tiebaAnimationState=0;
}



//获取个人信息
-(void)getMyHttpData
{
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    manager.requestSerializer=[AFHTTPRequestSerializer serializer];
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
    
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    NSString *token=[user objectForKey:@"token"];
    
    [manager GET:[NSString stringWithFormat:PersonalHomeMessage,_userId,token] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        [self.header endRefreshing];
        NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"个人信息=====%@",dic);
        if (dic) {
            _userDic=dic[@"user"];
            _userDic=[NSDictionary changeType:_userDic];
            _tieziDataArray=dic[@"topics"][@"data"];
            NSLog(@"用户的信息=====%@",_userDic);
            
            
            NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
            NSDictionary *defaultsDic=@{@"otherUserId":_userDic[@"user_profile"][@"user_id"],@"otherUserName":_userDic[@"user_profile"][@"nikename"],@"otherUserHeadImage":_userDic[@"user_profile"][@"avatar_url"]};
            NSArray *myDefaultsArray=[user objectForKey:@"myDefaultsArray"];
            NSMutableArray *myDefaultsMutableArray=[NSMutableArray arrayWithArray:myDefaultsArray];
            [myDefaultsMutableArray addObject:defaultsDic];
            myDefaultsArray=[NSArray arrayWithArray:myDefaultsMutableArray];
            [user setObject:myDefaultsArray forKey:@"myDefaultsArray"];
//            [user setObject:_userDic[@"user_profile"][@"user_id"] forKey:@"otherUserId"];
//            [user setObject:_userDic[@"user_profile"][@"nikename"] forKey:@"otherUserName"];
//            [user setObject:_userDic[@"user_profile"][@"avatar_url"] forKey:@"otherUserHeadImage"];
            [user synchronize];
            
            
            
            
            
            

            
            RCUserInfo *user1 = [[RCUserInfo alloc]init];
            user1.userId = _userDic[@"user_profile"][@"user_id"];
            user1.name = _userDic[@"user_profile"][@"nikename"];
            user1.portraitUri = _userDic[@"user_profile"][@"avatar_url"];
            [[RCIM sharedRCIM]refreshUserInfoCache:user1 withUserId:_userDic[@"user_profile"][@"user_id"]];
            
            [[RCIM sharedRCIM] clearUserInfoCache];
            [[RCIM sharedRCIM]clearGroupInfoCache];
            _dataArray=[NSMutableArray array];
            
            if ([dic[@"topics"][@"next_page_url"] isKindOfClass:[NSNull class]]) {
                _nextPageUrl=nil;
            }else{
                _nextPageUrl=dic[@"topics"][@"next_page_url"];
            }
            
            
            
            for (NSDictionary *dataDic in dic[@"topics"][@"data"]) {
                TieZiDetailModel *model=[[TieZiDetailModel alloc]initWithDictionary:dataDic];
                [_dataArray addObject:model];
                NSLog(@"zanState=================%@",dataDic[@"is_like"]);
            }
            
            dispatch_async(dispatch_get_main_queue(), ^{
                if (_hideHeaderView) {
                    
                }else{
                    self.tableHeaderView=[UIView new];
                    self.tableHeaderView=[self createTableHeaderView];
                }

                [self reloadData];
            });
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        [self.header endRefreshing];
        NSLog(@"error====%@",error.localizedDescription);
    }];
    
}

//下拉加载
-(void)getMoreData
{
    
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    manager.requestSerializer=[AFHTTPRequestSerializer serializer];
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
    if (_nextPageUrl) {
        [manager GET:_nextPageUrl parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            [self.footer endRefreshing];
            NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            NSLog(@"个人信息=====%@",dic);
            if (dic) {
                
                _nextPageUrl=dic[@"topics"][@"next_page_url"];
                if ([dic[@"topics"][@"next_page_url"] isKindOfClass:[NSNull class]]) {
                    _nextPageUrl=nil;
                }else{
                    _nextPageUrl=dic[@"topics"][@"next_page_url"];
                }
                
                for (NSDictionary *dataDic in dic[@"topics"][@"data"]) {
                    TieZiDetailModel *model=[[TieZiDetailModel alloc]initWithDictionary:dataDic];
                    [_dataArray addObject:model];
                    [_tieziDataArray addObject:dataDic];
                    NSLog(@"zanState=================%@",dataDic[@"is_like"]);
                }
                
                dispatch_async(dispatch_get_main_queue(), ^{
                    [self reloadData];
                });
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            [self.footer endRefreshing];
            NSLog(@"error====%@",error.localizedDescription);
        }];
        
    }else{
        [self.footer endRefreshing];
        return;
    }
    
    
}


///帖子点赞
-(void)getZanHttpData:(NSString *)tieziId
{
    NSLog(@"帖子的id======%@",tieziId);
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    manager.requestSerializer=[AFHTTPRequestSerializer serializer];
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    NSString *token=[user objectForKey:@"token"];
    
    
    [manager  POST:[NSString stringWithFormat:@"%@?token=%@&topic_id=%@",TieZiIsLike,token,tieziId] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"tieziZanData===============%@点赞结果========%@",dic,dic[@"status"][@"msg"]);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error.localizedDescription);
    }];
}
//取消点赞
-(void)getCancelZanHttpData:(NSString *)tieziId
{
    NSLog(@"帖子的id======%@",tieziId);
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    manager.requestSerializer=[AFHTTPRequestSerializer serializer];
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    NSString *token=[user objectForKey:@"token"];
    
    
    [manager DELETE:[NSString stringWithFormat:@"%@?token=%@&topic_id=%@",TieZiCancellike,token,tieziId] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"tieziCancelZanData===============%@=====取消赞结果======%@",dic,dic[@"status"][@"msg"]);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@",error.localizedDescription);
    }];
}

//关注用户
-(void)getAttentionUser:(NSString *)userId
{
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    manager.requestSerializer=[AFHTTPRequestSerializer serializer];
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    NSString *token=[user objectForKey:@"token"];
    
    [manager POST:[NSString stringWithFormat:AttentionUser,token,userId] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"加关注====%@",dic);
        dispatch_async(dispatch_get_main_queue(), ^{
            [_btn1 setTitle:@"取消关注" forState:UIControlStateNormal];
            _attentionState=YES;
        });
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error%@",error.localizedDescription);
    }];

}

//取消关注
-(void)cancelAttentionUser:(NSString *)userId
{
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    manager.requestSerializer=[AFHTTPRequestSerializer serializer];
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    NSString *token=[user objectForKey:@"token"];
    
    [manager DELETE:[NSString stringWithFormat:AttentionUser,token,userId] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"加关注====%@",dic);
        dispatch_async(dispatch_get_main_queue(), ^{
            [_btn1 setTitle:@"+关注" forState:UIControlStateNormal];
            _attentionState=NO;
        });
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"error%@",error.localizedDescription);
    }];
}

//举报
-(void)reportUser
{
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    manager.requestSerializer=[AFHTTPRequestSerializer serializer];
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
    NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
    NSString *token=[user objectForKey:@"token"];
    
    if (_userDic[@"id"]) {
        [manager POST:[NSString stringWithFormat:ReportUser,token,_userId] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            NSDictionary *dic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            NSLog(@"举报%@",dic);
            [self showTiShiMessage:@"举报成功"];
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"error%@",error.localizedDescription);
            [self showTiShiMessage:@"举报失败"];
        }];
    }else{
        return;
    }
}
@end
